package com.ruoyi.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.system.domain.BsQiyeMerchandise;
import com.ruoyi.system.domain.dto.BsCountNumDTO;
import com.ruoyi.system.domain.ro.BsQiyeMerchandiseRO;
import com.ruoyi.system.mapper.BsQiyeMerchandiseMapper;
import com.ruoyi.system.service.IBsQiyeMerchandiseService;
import io.github.classgraph.utils.Join;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文创数据商品 Service业务层处理
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class BsQiyeMerchandiseServiceImpl implements IBsQiyeMerchandiseService {

    private final BsQiyeMerchandiseMapper baseMapper;


    @Override
    public List<BsCountNumDTO> countMerchandise(List<Long> bsQiyeIds) {
        String join = Join.join(",", bsQiyeIds);
        return baseMapper.countMerchandise(join);
    }

    @Override
    public List<BsQiyeMerchandise> queryList(Long qiYeId) {
        return baseMapper.selectList(new QueryWrapper<BsQiyeMerchandise>().lambda()
                .eq(BsQiyeMerchandise::getQiyeId, qiYeId)
                .orderByDesc(BsQiyeMerchandise::getCreateTime)
        );
    }

    @Override
    public List<BsQiyeMerchandise> queryList() {
        return baseMapper.selectList(new QueryWrapper<BsQiyeMerchandise>().lambda()
                .orderByDesc(BsQiyeMerchandise::getCreateTime)
        );
    }

    @Override
    public boolean insertByRO(BsQiyeMerchandiseRO ro) {
        BsQiyeMerchandise add = BeanUtil.toBean(ro, BsQiyeMerchandise.class);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            ro.setId(add.getId());
        }
        return flag;
    }

    @Override
    public boolean updateByRO(BsQiyeMerchandiseRO ro) {
        BsQiyeMerchandise update = BeanUtil.toBean(ro, BsQiyeMerchandise.class);
        return baseMapper.updateById(update) > 0;
    }

    @Override
    public boolean deleteWithValidByIds(List<Long> singletonList) {
        return baseMapper.deleteBatchIds(singletonList) > 0;
    }

    @Override
    public BsQiyeMerchandise detail(Long id) {
        return baseMapper.selectById(id);
    }
}
